package com.dianrui.operation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dianrui.operation.R;
import com.dianrui.operation.bean.Menu;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class InspectionMenuAdapter extends BaseAdapter {

    Context context;
    List<Menu> list;

    public InspectionMenuAdapter(Context context, List<Menu> list) {
        this.context = context;
        this.list = list;
    }

    public void refresh(List<Menu> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.maininspection_grid_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (list.size() > 0) {
            Menu menu = list.get(position);
            holder.menuName.setText(menu.menu_name);
            holder.menuAction.setText(menu.menu_action);
        }
        return convertView;
    }

     class ViewHolder {
        @BindView(R.id.menu_name)
        TextView menuName;
         @BindView(R.id.menu_action)
         TextView menuAction;
        @BindView(R.id.menu_layout)
        LinearLayout menuLayout;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
